package com.linkoog.devtools.java_patcher;

import com.intellij.execution.Executor;
import com.intellij.execution.configurations.JavaParameters;
import com.intellij.execution.configurations.JavaRunConfigurationModule;
import com.intellij.execution.configurations.ParametersList;
import com.intellij.execution.configurations.RunConfiguration;
import com.intellij.execution.configurations.RunProfile;
import com.intellij.execution.runners.JavaProgramPatcher;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.libraries.LibraryTable;
import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar;
import com.intellij.util.PathsList;

public class DevToolsJavaProgramPatcher extends JavaProgramPatcher {


    @Override
    public void patchJavaParameters(Executor executor, RunProfile configuration, JavaParameters javaParameters) {
        RunConfiguration runConfiguration = (RunConfiguration) configuration;
        ParametersList vmParametersList = javaParameters.getVMParametersList();


        //vmParametersList.addParametersString("-javaagent:" + agentCoreJarPath);
        /*javaParameters.getModuleName();

        final Project project = runConfiguration.getProject();
        LibraryTable libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(project);
        Library[] libraries = libraryTable.getLibraries();


        vmParametersList.addAt(0, "-DTest=" + "demo");
        //vmParametersList.prepend("");   ((ApplicationConfiguration) configuration).getMainClass()
        //vmParametersList.addProperty();

        PathsList classPath = javaParameters.getClassPath();
        classPath.addFirst("First.jar");
        classPath.addTail("Tail.jar");*/


        //ModuleUtilCore.findModuleForPsiElement(psiClass.getContainingFile())

    }
}
